import java.time.LocalDate
import java.time.format.DateTimeFormatter
import scala.collection.mutable.ArrayBuffer

object util {
  case class DimDate(date: String)

  // 构建从dateBegin 到 dateEnd 的时间数组
  def dimDate(dateBegin: String, dateEnd: String): Seq[DimDate] = {
    // println(dateBegin, dateEnd)
    val buffer = ArrayBuffer[DimDate]()
    val formatter = DateTimeFormatter.ofPattern("yyyy-MM")
    val begin = LocalDate.parse(s"${dateBegin}-01")
    val end = LocalDate.parse(s"${dateEnd}-01")
    var currentDate = begin
    while (!currentDate.isAfter(end)) {
      buffer.append(DimDate(currentDate.format(formatter)))
      currentDate = currentDate.plusMonths(1)
    }
    buffer
  }
}
